<?php

class MvcRequestTester extends TestRunner{
	public function test_01_ObjectCreation(){
		$request = new Mvc_Request(array());
		
		self::assertInstanceOf($request, "Mvc_Request");
	}
	
	public function test_02_isGet_isPost_isAjax(){
		$tServer = $_SERVER;
		$tPost = $_POST;
		
		$request = new Mvc_Request(array());

		$_SERVER = array("REQUEST_METHOD" => "GET");
		self::assertEqual($request->isGet(), true);
		self::assertEqual($request->isPost(), false);
		self::assertEqual($request->isAjax(), false);
		
		$_SERVER = array("REQUEST_METHOD" => "POST");
		self::assertEqual($request->isGet(), false);
		self::assertEqual($request->isPost(), true);
		self::assertEqual($request->isAjax(), false);
		
		$_POST = array("rqAjax" => true);
		
		$_SERVER = array("REQUEST_METHOD" => "GET");
		self::assertEqual($request->isGet(), false);
		self::assertEqual($request->isPost(), false);
		self::assertEqual($request->isAjax(), true);

		$_SERVER = array("REQUEST_METHOD" => "POST");
		self::assertEqual($request->isGet(), false);
		self::assertEqual($request->isPost(), false);
		self::assertEqual($request->isAjax(), true);
		
		$_POST = $tPost;
		$_SERVER = $tServer;
	}
	
	public function test_03_getServer(){
		$store = $_SERVER;
		
		$request = new Mvc_Request(array());
		
		$_SERVER = array("SystemRoot" => "C:\\Windows");
		self::assertEqual($request->getServer("SystemRoot"), "C:\\Windows");
		
		$_SERVER = array();
		try{
			$request->getServer("NonExistantKey");
		}catch(Mvc_Exception $e){
			self::assertEqual($e->getMessage(), "Server variable NonExistantKey does not exist");
		}
		
		$_SERVER = "NotAnArray";
		self::assertEqual($request->getServer(), "NotAnArray");
		
		try{
			$request->getServer("NonExistantKeyInInvalidValue");
		}catch(Mvc_Exception $e){
			self::assertEqual($e->getMessage(), "Server variable NonExistantKeyInInvalidValue does not exist");
		}
		
		$_SERVER = $store;
	}
	
	public function test_04_getCookie(){
		$store = $_COOKIE;
		
		$request = new Mvc_Request(array());
		
		$_COOKIE = array("StoredKey" => "StoredVar");
		self::assertEqual($request->getCookie("StoredKey"), "StoredVar");
		
		$_COOKIE = array();
		try{
			$request->getCookie("NonExistantKey");
		}catch(Mvc_Exception $e){
			self::assertEqual($e->getMessage(), "Cookie variable NonExistantKey does not exist");
		}
		
		$_COOKIE = "NotAnArray";
		self::assertEqual($request->getCookie(), "NotAnArray");
		
		try{
			 $request->getCookie("NonExistantKeyInInvalidValue");
		}catch(Mvc_Exception $e){
			self::assertEqual($e->getMessage(), "Cookie variable NonExistantKeyInInvalidValue does not exist");
		}
		
		$_COOKIE = $store;
	}
	
	public function test_05_getFile(){
		$store = $_FILES;
		
		$request = new Mvc_Request(array());
		
		$_FILES = array("StoredKey" => "C:\\autorun.bat");
		self::assertEqual($request->getFile("StoredKey"), "C:\\autorun.bat");
		
		$_FILES = array();
		try{
			$request->getFile("NonExistantKey");
		}catch(Mvc_Exception $e){
			self::assertEqual($e->getMessage(), "File variable NonExistantKey does not exist");
		}
		
		$_FILES = "NotAnArray";
		self::assertEqual($request->getFile(), "NotAnArray");
		
		try{
			$request->getFile("NonExistantKeyInInvalidValue");
		}catch(Mvc_Exception $e){
			self::assertEqual($e->getMessage(), "File variable NonExistantKeyInInvalidValue does not exist");
		}
		
		$_FILES= $store;
	}
}

return new MvcRequestTester();